<?php
include("interface.class.php");
include("table.class.php");
include("database.class.php");

$inf = new webinterface();
$inf->set_title("Rules");

$tab = new table();
$tab->t_id="rules";


$db = new database();
$link = $db->connect();

$tab->set_head(array('Order','Source','Destination','Proxy','CT','Action','Log','Description'));
$res = mysql_query("SELECT * FROM connection_rules", $link);
while ($row = mysql_fetch_array($res)) {
	$r_order	= $row['order'];	
	$r_src		= $row['src'];
	if ($r_src == ""){
		$r_src = "ALL";
	} else {
		$res2 = mysql_query("SELECT name FROM host_group WHERE idhost_group='" . $r_src . "'");
		$res2 = mysql_fetch_array($res2);
		$r_src = "<a href='edit_host_group.php?idhost_group=" . $r_src . "'>" . $res2['name'] . "</a>";
	}
	$r_dst		= $row['dst'];
	if ($r_dst == ""){
		$r_dst = "ALL";
	} else {
		$res2 = mysql_query("SELECT name FROM host_group WHERE idhost_group='" . $r_dst . "'");
		$res2 = mysql_fetch_array($res2);
		$r_dst = "<a href='edit_host_group.php?idhost_group=" . $r_dst . "'>" . $res2['name'] . "</a>";
	}
	$r_gateway	= $row['gateway'];
	if ($r_gateway == ""){
		$r_gateway = "ALL";
	} else {
		$res2 = mysql_query("SELECT name FROM proxy_group WHERE idproxy_group='" . $r_gateway . "'");
		$res2 = mysql_fetch_array($res2);
		$r_gateway = "<a href='edit_proxy_group.php?idproxy_group=" . $r_gateway . "'>" . $res2['name'] . "</a>";
	}
	$r_ct		= $row['conntrack'];
	if($r_ct == 0){
		$r_ct = "No";
	} else {
		$r_ct = "Yes";
	}
	$r_action	= strtoupper($row['action']);
	$r_log		= $row['log'];
	if($r_log == 0){
		$r_log = "No";
	} else {
		$r_log = "Yes";
	}
	$r_description	= $row['description'];

	$table_row = array($r_order, $r_src, $r_dst, $r_gateway, $r_ct, $r_action, $r_log, $r_description);	

	$tab->add_row($table_row);

}
mysql_close($link);
$inf->add_docready_script($tab->script());
$inf->add_content($tab->html());

/* ojete table 
$tab = new table();
$tab->t_id="ojete";
$tab->set_head(array('ojete','moreno','mola'));
$tab->add_row(array('linea1','columna2','guay'));
$tab->add_row(array('linea2','columna2','guay'));
$tab->add_row(array('linea3','columna2','ojete'));
$inf->add_docready_script($tab->script());
$inf->add_content($tab->html());
end ojete table */

/* moreno table 
$tab2 = new table();
$tab2->t_id="moreno";
$tab2->set_head(array('caca','culo','pis'));
$tab2->add_row(array('linea1','columna2','guay'));
$tab2->add_row(array('linea2','columna2','guay'));
$tab2->add_row(array('linea3','columna2','ojete'));
$inf->add_docready_script($tab2->script());
$inf->add_content($tab2->html());
 end ojete table */

$inf->commit();
?>
